package com.ruoyi.control.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; //添加
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.control.mapper.MainventilatorOneMapper;
import com.ruoyi.control.domain.MainventilatorOne;
import com.ruoyi.control.service.IMainventilatorOneService;

/**
 * 主通风机1号风机Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-08
 */
@Service
public class MainventilatorOneServiceImpl extends ServiceImpl<MainventilatorOneMapper, MainventilatorOne> implements IMainventilatorOneService //修改
{
    @Autowired
    private MainventilatorOneMapper mainventilatorOneMapper;

    /**
     * 查询主通风机1号风机
     * 
     * @param address 主通风机1号风机主键
     * @return 主通风机1号风机
     */
    @Override
    public MainventilatorOne selectMainventilatorOneByAddress(String address)
    {
        return mainventilatorOneMapper.selectMainventilatorOneByAddress(address);
    }

    /**
     * 查询主通风机1号风机列表
     * 
     * @param mainventilatorOne 主通风机1号风机
     * @return 主通风机1号风机
     */
    @Override
    public List<MainventilatorOne> selectMainventilatorOneList(MainventilatorOne mainventilatorOne)
    {
        return mainventilatorOneMapper.selectMainventilatorOneList(mainventilatorOne);
    }

    /**
     * 新增主通风机1号风机
     * 
     * @param mainventilatorOne 主通风机1号风机
     * @return 结果
     */
    @Override
    public int insertMainventilatorOne(MainventilatorOne mainventilatorOne)
    {
        return mainventilatorOneMapper.insertMainventilatorOne(mainventilatorOne);
    }

    /**
     * 修改主通风机1号风机
     * 
     * @param mainventilatorOne 主通风机1号风机
     * @return 结果
     */
    @Override
    public int updateMainventilatorOne(MainventilatorOne mainventilatorOne)
    {
        mainventilatorOne.setUpdateTime(DateUtils.getNowDate());
        return mainventilatorOneMapper.updateMainventilatorOne(mainventilatorOne);
    }

    /**
     * 批量删除主通风机1号风机
     * 
     * @param addresss 需要删除的主通风机1号风机主键
     * @return 结果
     */
    @Override
    public int deleteMainventilatorOneByAddresss(String[] addresss)
    {
        return mainventilatorOneMapper.deleteMainventilatorOneByAddresss(addresss);
    }

    /**
     * 删除主通风机1号风机信息
     * 
     * @param address 主通风机1号风机主键
     * @return 结果
     */
    @Override
    public int deleteMainventilatorOneByAddress(String address)
    {
        return mainventilatorOneMapper.deleteMainventilatorOneByAddress(address);
    }

    @Override
    public List<MainventilatorOne> getList() {
        List<MainventilatorOne> mainventilatorOneList = mainventilatorOneMapper.selectMainventilatorOneList(null);
        List<String> tagNames = Arrays.asList("1#一级电机A相温度","1#一级电机B箱温度","1#一级电机C相温度", "1#一级电机前轴温度", "1#一级电机后轴温度",
                "1#变频器输入电压", "1#变频器输入电流","1#变频器输出功率","1#变频器输出电压", "1#变频器输出电流", "1#变频器设定频率","1#横向振幅","1#纵向振幅",
                "1#风速","1#负压", "1#风量","1#环境温度","2#变频器输入电压", "2#变频器输入电流","2#变频器输出功率","2#变频器设定频率","2#变频器输出电压","1#1级效率","1#2级效率",
                "2#变频器输出电流","1#二级电机A相温度","1#二级电机B箱温度","1#二级电机C相温度","1#二级电机前轴温度","1#二级电机后轴温度","2#变频器运行频率","1#变频器运行频率",

                "2#一级电机A相温度","2#一级电机B箱温度","2#一级电机C相温度", "2#一级电机前轴温度", "2#一级电机后轴温度","1#2#1级效率","2#2级效率",
                "3#变频器输入电压", "3#变频器输入电流","3#变频器输出功率","3#变频器输出电压", "3#变频器输出电流", "3#变频器设定频率","2#横向振幅","2#纵向振幅",
                "4#变频器输入电压", "4#变频器输入电流","4#变频器输出功率","4#变频器设定频率","4#变频器输出电压","3#变频器运行频率","4#变频器运行频率",
                "4#变频器输出电流","2#二级电机A相温度","2#二级电机B箱温度","2#二级电机C相温度","2#二级电机前轴温度","2#二级电机后轴温度");
        List<MainventilatorOne> collect = mainventilatorOneList.stream().filter(belt -> tagNames.contains(belt.getTagName())).collect(Collectors.toList());
        for (MainventilatorOne mainventilatorOne : collect) {
            String replace = "主扇".concat(mainventilatorOne.getTagName()).replace("#","号");
            mainventilatorOne.setTagName(replace);
            if (mainventilatorOne != null && mainventilatorOne.getValue() != null){
                Double dValue = Double.valueOf(mainventilatorOne.getValue());
                mainventilatorOne.setValue(String.format("%.2f",dValue));
            }
        }
        return collect;
    }

    @Override
    public List<MainventilatorOne> getDF() {
        List<MainventilatorOne> mainventilatorOneList = mainventilatorOneMapper.selectMainventilatorOneList(null);
        List<String> tagNames = Arrays.asList("1#蝶阀开到位", "1#蝶阀关到位","2#蝶阀开到位","2#蝶阀关到位");
        List<MainventilatorOne> collect = mainventilatorOneList.stream().filter(belt -> tagNames.contains(belt.getTagName())).collect(Collectors.toList());
        for (MainventilatorOne mainventilatorOne : collect) {
            String replace = "主扇".concat(mainventilatorOne.getTagName()).replace("#","号");
            mainventilatorOne.setTagName(replace);
            mainventilatorOneList.add(mainventilatorOne);
        }
        return collect;
    }

    @Override
    public List<MainventilatorOne> getDyDpTfValueList() {
        return mainventilatorOneMapper.getDyDpTfValueList();
    }

    @Override
    public List<MainventilatorOne> getChDpTfValueList() {
        return mainventilatorOneMapper.getChDpTfValueList();
    }
}
